package hdu.edu.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import hdu.edu.Model.Person;

@Controller
@RequestMapping("/register")
public class RegisterController {
	
	@Autowired
	private hdu.edu.Dao.personDao personDao;
	
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public ModelAndView add(){
		ModelAndView mav=new ModelAndView("login/register");
		return mav;
		
	}
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public ModelAndView add(@RequestParam String username,
			@RequestParam String password){
		Person person=new Person();
		person.setUserName(username);
		person.setPassword(password);
		personDao.addPerson(person);
		ModelAndView mav=new ModelAndView("login/success");
		return mav;
	}
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public ModelAndView login(){
		ModelAndView mav=new ModelAndView("redirect:/login");
		return mav;
		
	}
	
}
